<template>
	<view style="padding-bottom: 160rpx;">
		<u--form errorType="toast" labelWidth="88" :labelStyle="{fontSize:'28rpx'}" labelPosition="left" :model="postData" :rules="rules" ref="uForm">
			<view class="bt-block m-3 px-2">
			 	<u-form-item required label="项目名称" prop="projectName">
			 		<u--input v-model="postData.projectName" border="none" inputAlign='right' placeholder="请输入"></u--input>
			 	</u-form-item>
			 	<view class="bt-line-1" > </view>
			 	<u-form-item required label="项目地址" prop="projectAddr">
			 		<u--input v-model="postData.projectAddr" border="none" inputAlign='right' placeholder="请输入"></u--input>
			 	</u-form-item>
				<view class="bt-line-1" > </view>
				<u-form-item required label="项目规模" prop="projectScale">
					<u--input v-model="postData.projectScale" border="none" inputAlign='right' placeholder="请输入"></u--input>
				</u-form-item>
				<view class="bt-line-1" > </view>
				<u-form-item required label="合同金额" prop="contractAmountw">
					<u--input type="number" v-model="postData.contractAmountw" border="none" inputAlign='right' placeholder="请输入"></u--input>
					万元
				</u-form-item>
				<view class="bt-line-1" > </view>
				<u-form-item required label="发包单位" prop="employer">
					<u--input v-model="postData.employer" border="none" inputAlign='right' placeholder="请输入"></u--input>
				</u-form-item>
				<view class="bt-line-1" > </view>
				<u-form-item required label="分包单位" prop="subcontractor">
					<u--input v-model="postData.subcontractor" border="none" inputAlign='right' placeholder="请输入"></u--input>
				</u-form-item>
			</view>
			<view class="bt-block m-3 px-2">
				<!-- <u-form-item labelPosition="left" required label="项目经理" prop="projectManagerUserId">
					<view class="text-right flex-1">{{postData.projectManagerUserName}}</view>
				</u-form-item>
				<view class="mb-3" @tap="selectUser('projectManager')">
					<u--image width="152rpx" height="152rpx" src="/static/images/ui/edu/select-user.png"></u--image>
				</view> -->
				<!-- <view class="bt-line-1" > </view>
				<u-form-item labelPosition="left" required label="生产经理" prop="productionManagerUserId">
					<view class="text-right flex-1">{{postData.productionManagerUserName}}</view>
				</u-form-item>
				<view class="mb-3" @tap="selectUser('productionManager')">
					<u--image width="152rpx" height="152rpx" src="/static/images/ui/edu/select-user.png"></u--image>
				</view>
				<view class="bt-line-1" > </view>
				<u-form-item  labelPosition="left" required label="技术总工" prop="chiefEngineerUserId">
					<view class="text-right flex-1">{{postData.chiefEngineerUserName}}</view>
				</u-form-item>
				<view class="mb-3" @tap="selectUser('chiefEngineer')">
					<u--image width="152rpx" height="152rpx" src="/static/images/ui/edu/select-user.png"></u--image>
				</view>
				<view class="bt-line-1" > </view> -->
				<u-form-item  labelPosition="top" required label="安全管理员">
					<view class="text-right flex-1">{{postData.safetyManagerUserName}}</view>
				</u-form-item>
				<view class="mb-3" @tap="selectUser('safetyManager')">
					<u--image width="152rpx" height="152rpx" src="/static/images/ui/edu/select-user.png"></u--image>
				</view>
				<view class="bt-line-1" > </view>
				<u-form-item  labelPosition="top" required label="财务管理员" prop="financeManagerUserId">
					<view class="text-right flex-1">{{postData.financeManagerUserName}}</view>
				</u-form-item>
				<view class="mb-3" @tap="selectUser('financeManager')">
					<u--image width="152rpx" height="152rpx" src="/static/images/ui/edu/select-user.png"></u--image>
				</view>
				<!-- <view class="bt-line-1" > </view>
				<u-form-item labelWidth="90" labelPosition="top" required label="项目管理员" prop="projectAdminUserId">
					<view class="text-right flex-1">{{postData.projectAdminUserName}}</view>
				</u-form-item>
				<view class="mb-3" @tap="selectUser('projectAdmin')">
					<u--image width="152rpx" height="152rpx" src="/static/images/ui/edu/select-user.png"></u--image>
				</view> -->
			</view>
		</u--form>
		<view class="bt-footer">
			<bg-btn @click="saveData">提交</bg-btn>
		</view>
	</view>
</template>

<script>
	import { addProject } from '@/api/project'
	export default {
		data() {
			return {
				postData:{
					projectName:'',
					projectAddr:'',
					projectScale:'',
					contractAmountw:'',
					employer:'',
					subcontractor:'',
					projectManagerUserId:'',
					productionManagerUserId:'',
					chiefEngineerUserId:'',
					financeManagerUserId:'',
					projectAdminUserId:'',
					projectManagerUserName:'',
					productionManagerUserName:'',
					chiefEngineerUserName:'',
					financeManagerUserName:'',
					projectAdminUserName:'',
					safetyManagerUserId:'',
					safetyManagerUserName:'',
					safetyDocUrl:''
				},
				model:{},
				rules:{
					"projectName": {
						type: 'string',
						required: true,
						message: '请填写项目名称',
						trigger: ['blur', 'change']
					},
					"projectAddr": {
						type: 'string',
						required: true,
						message: '请填写项目地址',
						trigger: ['blur', 'change']
					},
					"projectScale": {
						type: 'string',
						required: true,
						message: '请填写项目规模',
						trigger: ['blur', 'change']
					},
					"contractAmountw": {
						type: 'string',
						required: true,
						message: '请填写合同金额',
						trigger: ['blur', 'change']
					},
					"employer": {
						type: 'string',
						required: true,
						message: '请填写发包单位',
						trigger: ['blur', 'change']
					},
					"subcontractor": {
						type: 'string',
						required: true,
						message: '请填写分包单位',
						trigger: ['blur', 'change']
					},
					// "projectManagerUserId": {
					// 	type: 'number',
					// 	required: true,
					// 	message: '请选择项目经理',
					// 	trigger: ['blur', 'change']
					// },
					// "productionManagerUserId": {
					// 	type: 'number',
					// 	required: true,
					// 	message: '请选择生产经理',
					// 	trigger: ['blur', 'change']
					// },
					// "chiefEngineerUserId": {
					// 	type: 'number',
					// 	required: true,
					// 	message: '请选择技术总工',
					// 	trigger: ['blur', 'change']
					// },
					"financeManagerUserId": {
						type: 'number',
						required: true,
						message: '请选择财务管理员',
						trigger: ['blur', 'change']
					},
					// "projectAdminUserId	": {
					// 	type: 'number',
					// 	required: true,
					// 	message: '请选择项目管理员',
					// 	trigger: ['blur', 'change']
					// }
				}
			}
		},
		mounted() {
			uni.$on('selected-user-work', res=>{
				console.log(res)
				if(typeof res == 'object'){
					Object.assign(this.postData, res)
				}
			})
		},
		methods: {
			selectUser(work){
				uni.navigateTo({
					url:"/pages/common/user-select/user-select?work="+work
				})
			},
			saveData(){
				this.$refs.uForm.validate().then(res => {
					addProject(this.postData).then(res=>{
						this.$modal.msgSuccess("创建成功")
						uni.$emit("refresh-opener", true)
						setTimeout(()=>{
							uni.navigateBack()
						}, 1000)
					})
					
					
				}).catch(errors => {
					console.log(errors)
					uni.$u.toast(errors[0].message)
				})
			}
		}
	}
</script>

<style>

</style>
